<template>
  <div class="app-container">
    <el-card shadow="never" v-loading="loading">
      <el-row :gutter="5">
          <el-row>
            <el-card shadow="never">
              <el-table :data="tableData" :stripe="true" style="width: 100%">
                <el-table-column prop="name" align="center" label="专家名称" />
                <el-table-column prop="telNum" align="center" label="手机号" />
                <el-table-column prop="workUnit" align="center" label="工作单位名称" />
                <el-table-column prop="organName" align="center" label="推荐单位名称" />
                <el-table-column prop="createTime" align="center" label="申请时间" />
                <el-table-column prop="status" align="center" label="审核状态" />
                <el-table-column align="center" label="操作" width="300">
                  <template slot-scope="scope">

                      <!--  v-if="scope.row.status != '已审核'" -->
                    <el-button type="text" @click="showEditDialog(scope.$index, scope.row)"   v-if="scope.row.status != '已审核'">填报</el-button>
                    <el-button type="text" @click="showReadDialog(scope.$index, scope.row)"  v-if="scope.row.status === '已审核'">详情</el-button>
                     <!-- <el-button type="text" @click="exportPdf(scope.row.uid)"  v-if="scope.row.status != '已审核'">导出专家信息表pdf</el-button> -->
                     <!-- <el-button type="text" @click="uploadPdf(scope.row.uid)">上传pdf</el-button> -->
                    <el-button type="text" @click="showEditPwdDialog(scope.$index, scope.row)" v-if="scope.row.status === '已审核'" >修改密码</el-button>
                    <el-button type="text" @click="showEditTelDialog(scope.$index, scope.row)"  v-if="scope.row.status === '已审核'">修改手机号</el-button>
                    <!--编辑-->
                   <!-- <el-button type="text" class="table-delete-btn"
                      @click="handleDelete(scope.$index, scope.row)"></el-button> --><!--删除-->
                  </template>
                </el-table-column>

              </el-table>
              <XPagination ref="pageInfo" :total="total" :get-data="getList" />
            </el-card>
          </el-row>
        </el-col>
      </el-row>
    </el-card>
    <el-dialog width="60%" :title="dialogTitle" :visible.sync="dialogVisible">
      <el-form label-width="150px" ref="form" :model="form" :rules="formRules" label-position="top" style="padding:10px 80px;" :disabled="this.dialogTitle==='专家信息表详情'" >
<!--      <el-tabs style="margin-bottom: 20px;">
        <el-tab-pane label="专家信息" />
      </el-tabs> -->
      <!--     <el-row>
                <el-col :span="20">
                  <el-radio-group v-model="form.name">
                            <el-radio :label="0">第一批推荐</el-radio>
                            <el-radio :label="1">各类推荐</el-radio>
                  </el-radio-group>
                </el-col>
            </el-row> -->
            <el-row :gutter="60">
                <el-col :span="12">
                    <el-form-item label="姓名" prop="name">
                      <el-input v-model="form.name" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="个人照片" prop="personalImg">
                      <x-upload v-model="form.personalImg" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="性别" prop="sex">
                      <el-select v-model="form.sex" style="width: 100%;">
                        <el-option :label="'男'" value="男"></el-option>
                        <el-option :label="'女'" value="女"></el-option>
                      </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="出生日期" prop="birthday" >
                        <el-date-picker style="width: 100%;" v-model="form.birthday" value-format="yyyy-MM-dd">
                        </el-date-picker>
                     </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="参加工作时间" prop="serviceYears" >
                        <el-date-picker style="width: 100%;" v-model="form.serviceYears" value-format="yyyy-MM-dd">
                        </el-date-picker>
                     </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="政治面貌" prop="politicalOutlook">
                        <el-input style="width: 100%;" v-model="form.politicalOutlook" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="民族" prop="nation">
                        <el-select style="width: 100%;" v-model="form.nation">
                          <el-option v-for="(item, index) in nationList" :key="index" :label="item.name" :value="item.name" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="职务/职称" prop="position">
                      <el-select style="width: 100%;" v-model="form.position">
                        <el-option v-for="(item, index) in positionList" :key="index" :label="item.name" :value="item.name" />
                      </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="工作单位" prop="workUnit">
                      <el-input v-model="form.workUnit" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="推荐单位" prop="organName">
                      <el-input v-model="form.organName">
                        <template slot="append">
                          <el-button @click="openOrgList">选择机构</el-button>
                        </template>
                      </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="专业领域" prop="appointmentTime">
                      <el-select style="width: 100%;" v-model="form.appointmentTime">
                        <el-option v-for="(item, index) in personalList" :key="index" :label="item.name" :value="item.name" />
                      </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="研究方向" prop="profession">
                        <el-input v-model="form.profession" />
                      </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="学位学历" prop="highestDegree">
                        <el-select style="width: 100%;" v-model="form.highestDegree">
                          <el-option v-for="(item, index) in highestDegreeList" :key="index" :label="item.name" :value="item.name" />
                        </el-select>
                      </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="毕业院校" prop="graduationInstitution">
                      <el-input v-model="form.graduationInstitution" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="通讯地址" prop="workAddress">
                         <el-input v-model="form.workAddress" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="联系电话" prop="telNum">
                      <el-input :readonly="true" v-model="form.telNum" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="电子邮箱" prop="email">
                      <el-input v-model="form.email" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="工作单位科普主管部门(如党办、宣传处)" prop="departmentName">
                         <el-input v-model="form.departmentName" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="联系人姓名" prop="organLevel">
                       <el-input v-model="form.organLevel" />
                     </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="联系人电话" prop="officePhone">
                       <el-input v-model="form.officePhone" />
                     </el-form-item>
                </el-col>
<!--                <el-col :span="12">
                    <el-form-item label="专家等级" prop="dependency">
                       <el-select style="width: 100%;" v-model="form.dependency">
                         <el-option v-for="(item, index) in ['省级', '市级','区县级']" :key="index" :label="item" :value="item" />
                       </el-select>
                     </el-form-item>
                </el-col> -->
                <el-col :span="12">
                    <el-form-item label="区域" prop="expertType">
                       <el-cascader style="width: 100%;" ref="expertType" v-model="expertType" :options="regionOptions" placeholder="请选择地区"
                         :props="props" @change="expertTypeChange"></el-cascader>
                     </el-form-item>
                </el-col>
            </el-row>
            <!-- <el-row>
              <el-col :span="24">
                <el-form-item label="工作简历" prop="briefIntroduction">
                  <el-input type="textarea" :autosize="{ minRows: 8, maxRows: 18 }" v-model="form.briefIntroduction" />
                </el-form-item>
              </el-col>
            </el-row> -->
            <!-- <el-row>
              <el-col :span="24">
                <el-form-item label="专业领域取得成绩(不超过500字)" prop="otherAccount">
                  <el-input type="textarea" :autosize="{ minRows: 8, maxRows: 18 }" v-model="form.otherAccount" />
                </el-form-item>
              </el-col>
            </el-row> -->
            <!-- <el-row>
              <el-col :span="24">
                <el-form-item label="健康科普专长和代表作品(需线下准备)" prop="personalSpecialty">
                  <el-input :readonly="true" type="textarea" :autosize="{ minRows: 4, maxRows: 18 }" v-model="personalSpecialty" />
                </el-form-item>
              </el-col>
            </el-row> -->
            <!-- <el-row>
              <el-col :span="24">
                <el-form-item label="健康科普代表作品" prop="tiktokAccount">
                  <el-input type="textarea" :autosize="{ minRows: 8, maxRows: 18 }" v-model="form.tiktokAccount" />
                </el-form-item>
              </el-col>
            </el-row> -->
            <!-- <el-row>
              <el-col :span="24">
                <el-form-item label="社会兼职情况" prop="wechatAccount">
                  <el-input type="textarea" :autosize="{ minRows: 8, maxRows: 18 }" v-model="form.wechatAccount" />
                </el-form-item>
              </el-col>
            </el-row> -->

            <el-row :gutter="60">
              <el-col :span="12">
                <el-form-item label="单位公示文件pdf" prop="noticeFile">
                    <upLoadPdfa  v-model="form.noticeFile" >
                    </upLoadPdfa>
                    <span style="color: #01c7ab;cursor:pointer" v-if="form.noticeFile" @click="downLoad(form.noticeFile)">已上传(点击下载)</span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="专家信息表文件pdf" prop="highestEducationLevel">
                    <upLoadPdfa  v-model="form.highestEducationLevel" >
                    </upLoadPdfa>
                    <span style="color: #01c7ab;cursor:pointer" v-if="form.highestEducationLevel" @click="downLoad(form.highestEducationLevel)">已上传(点击下载)</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="text-align: center;margin-top: 60px;" :gutter="60">
                <el-col :span="12">
                    <el-button type="primary" @click="handleZancun">暂  存</el-button>
                </el-col>
                <el-col :span="12">
                    <el-button type="primary" @click="handleSubmit">提交审批</el-button>
                </el-col>
            </el-row>
           </el-form>

    </el-dialog>

    <el-dialog width="40%" title="修改密码" :visible.sync="dialogPwsVisible">
      <el-form label-width="150px" ref="form" :model="form" :rules="formRulesPwd">

        <el-form-item label="登录账户" prop="logName" disabled>
          <el-input v-model="form.logName" disabled/>
        </el-form-item>
        <el-form-item label="新密码" prop="pwd">
          <el-input v-model="form.pwd"  />
        </el-form-item>
        <!-- <el-form-item label="确认密码" prop="pwd">
          <el-input v-model="form.verifyPwd" type="password" />
        </el-form-item> -->
      </el-form>
      <template slot="footer">
        <el-button type="primary" @click="passwordSave">保存</el-button>
      </template>
    </el-dialog>

    <el-dialog width="40%" title="修改手机号" :visible.sync="dialogTelVisible">
      <el-form label-width="150px" ref="form" :model="form" :rules="formRulesTel">

        <el-form-item label="登录账户" prop="logName" disabled>
          <el-input v-model="form.logName" disabled/>
        </el-form-item>
        <el-form-item label="新手机号" prop="telNum">
          <el-input v-model="form.telNum" type="text" />
        </el-form-item>
        <el-form-item label="手机验证码" prop="captcha">
          <div style="display: flex;align-items: center;justify-content: center;">
              <el-input v-model="form.captcha"  placeholder=""/>
              <el-button @click="sendCode" :disabled="isSending || countdown > 0">
                    {{ isSending ? '发送中...' : countdown > 0 ? `${countdown}秒后重试` : '发送验证码' }}
              </el-button>
          </div>
        </el-form-item>
      </el-form>
      <template slot="footer">
        <el-button type="primary" @click="telSave">提交</el-button>
      </template>
    </el-dialog>

    <el-dialog title="推荐单位信息" :visible.sync="dialogTableVisible" width="85%">
      <el-card shadow="never" v-loading="loading">
        <el-row :gutter="5">
          <el-col :span="24" class="main-card-view">
            <el-row>
              <el-card shadow="never" class="top-search-card">
                <el-row>
                  <el-form :inline="true" :model="searchOrgForm" class="demo-form-inline search-view">
                    <el-form-item label="单位名称">
                      <el-input v-model="searchOrgForm.organName" placeholder="请输入单位名称"></el-input>
                    </el-form-item>
                    <el-form-item label="等级">
                      <el-input v-model="searchOrgForm.grade" placeholder="请输入等级"></el-input>
                    </el-form-item>
                    <el-form-item label="单位信息">
                      <el-input v-model="searchOrgForm.unitName" placeholder="请输入单位信息"></el-input>
                    </el-form-item>
                    <el-form-item label="区域">
                      <el-input v-model="searchForm.area" placeholder="请输入区域"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button type="primary" @click="handleOrgSearch" class="search-button">
                        查询
                      </el-button>
                    </el-form-item>
                  </el-form>
                </el-row>
              </el-card>
            </el-row>

            <el-row>
              <el-card shadow="never">
                <el-table :data="tableOrgData" :stripe="true" style="width: 100%">
                  <el-table-column prop="classification" align="center" label="单位分类" />
                  <el-table-column prop="organName" align="center" label="单位名称" />
                  <el-table-column prop="grade" align="center" label="等级" />
                  <el-table-column prop="unitName" align="center" label="单位信息" />
                  <el-table-column prop="phone" align="center" label="电话" />
                  <el-table-column prop="area" align="center" label="区域">
                    <template slot-scope="scope">
                      {{ [scope.row.province, scope.row.city, scope.row.area].join(">") }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="操作" width="200">
                    <template slot-scope="scope">
                      <el-button type="text" @click="selectOrg(scope.$index, scope.row)">选择
                      </el-button><!--编辑-->
                    </template>
                  </el-table-column>
                </el-table>
                <XPagination ref="orgPageInfo" :total="orgTotal" :get-data="getOrgList" />
              </el-card>
            </el-row>
          </el-col>
        </el-row>
      </el-card>
    </el-dialog>
  </div>
</template>

<script>
import XPagination from "../../components/xpagination/XPagination";
import * as expertInfo from "../../api/expertInfo"
import * as formUtils from "../../utils/formUtils"
import XUpload from "../../components/xupload/XUpload";
import * as organInfo from "../../api/organInfo";
import * as dictionaryInfo from "../../api/dictionaryInfo"
import * as areaInfo from "../../api/areaInfo"
import upLoadPdfa from "../../components/upLoadPdfa.vue"
import request from '../../utils/request'
import axios from 'axios'
 import * as sms from "../../api/sms"
export default {
  name: "list",
  components: { XUpload, XPagination, upLoadPdfa },
  data () {
    return {
      //手机验证码
      isSending: false,
      countdown: 0,

      searchForm: {
        name: "",
        organName: "",
        departmentName: "",
      },
      gradeList: [],
      tableData: [],
      loading: false,
      dialogVisible: false,
      dialogPwsVisible:false,
      dialogTelVisible:false,
      userInfo: {},
      total: 0,
      dialogTitle: "添加专家资料",
      personalSpecialty: "",

      form: {
        uid: "",
        name: "",
        idNum: "",
        organName: "",
        organUid: "",
        expertType: "",
        personalImg: "",
        sex: "",
        birthday: "",
        nation: "",
        politicalOutlook: "",
        educationLevel: "",
        graduationInstitution: "",
        workUnit: "",
        majorStudied: "",
        highestEducationLevel: "",
        highestDegree: "",
        profession: "",
        duties: "",
        position: "",
        serviceYears: "",
        officePhone: "",
        telNum: "",
        appointmentTime: "",
        personalSpecialty:"",
        email: "",
        beGoodAt: "",
        workAddress: "",
        wechatAccount: "",
        tiktokAccount: "",
        otherAccount: "",
        mailAddress: "",
        departmentName: "",
        departmentUid: "",
        briefIntroduction: "",
        logName: "",
        pwd: "",
        status: "",
        province: "",
        city: "",
        area: "",
        organLevel: "",
        organClassify: "",
        grade: "",
        verifyPwd:"",
        noticeFile:"",
        captcha:"",
      },
      editStatus: "add",
      formRulesPwd: {
          logName: [
            { required: true, message: '不能为空', trigger: ['change', 'blur'] },
          ],
          pwd: [
              { required: true, message: '不能为空', trigger: ['change', 'blur'] },
              {trigger: ['change', 'blur'],
                message: '密码必须由数字、字母、特殊字符组合,请输入6-16位',
                validator: (rule, value, callback) => {
                  var passwordreg = /(?=.*\d)(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{6,16}/
                  if (!passwordreg.test(value)) {
                    callback(new Error('密码必须由数字、字母、特殊字符组合,请输入6-16位'))
                  }else{
                    callback()
                  }
                }
              }
          ],
      },

      formRulesTel: {
          logName: [
            { required: true, message: '不能为空',trigger: ['change', 'blur'] },
          ],
          pwd: [
              { required: true, message: '不能为空',trigger: ['change', 'blur'] },
              {
                trigger: ['change', 'blur'],
                message: '密码必须由数字、字母、特殊字符组合,请输入6-16位',
                validator: (rule, value, callback) => {
                  var passwordreg = /(?=.*\d)(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{6,16}/
                  if (!passwordreg.test(value)) {
                    callback(new Error('密码必须由数字、字母、特殊字符组合,请输入6-16位'))
                  }else{
                    callback()
                  }
                }
              }
          ],
          telNum: [
            { required: true, message: '不能为空', trigger: ['change', 'blur'] },
            {
                trigger: ['change', 'blur'],
                message: '手机号码格式不正确',
                validator: (rule, value, callback) => {
                  var tel = /^1[3456789]\d{9}$/
                  if (!tel.test(value)) {
                    callback(new Error('手机号码格式不正确'))
                  }else{
                    callback()
                  }
                }
            }
          ],
          captcha: [
            { required: true, message: '不能为空', trigger: ['change', 'blur'] },
          ],
      },

      formRules: {
        name: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        organName: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        idNum: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        expertType: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        // personalImg: [
        //   { required: true, message: '不能为空', trigger: 'blur' },
        // ],
        sex: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        nation: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],

        logName: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        telNum: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
          {
              trigger: ['change', 'blur'],
              message: '手机号码格式不正确',
              validator: (rule, value, callback) => {
                var tel = /^1[3456789]\d{9}$/
                if (!tel.test(value)) {
                  callback(new Error('手机号码格式不正确'))
                }else{
                  callback()
                }
              }
          }
        ],
        personalImg: [
          { required: true, message: '不能为空', trigger: ['change', 'blur']},
        ],
        birthday: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        serviceYears: [
          { required: true, message: '不能为空',trigger: ['change', 'blur'] },
        ],
        politicalOutlook: [
          { required: true, message: '不能为空', trigger: ['change', 'blur']},
        ],
        position: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        workUnit: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        appointmentTime: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        profession: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        highestDegree: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        graduationInstitution: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        workAddress: [
          { required: true, message: '不能为空',trigger: ['change', 'blur'] },
        ],
        email: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        departmentName: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        organLevel: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        officePhone: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] },
        ],
        pwd: [
            { required: true, message: '不能为空', trigger: 'blur' },
            {
             trigger: ['change', 'blur'],
              message: '密码必须由数字、字母、特殊字符组合,请输入6-16位',
              validator: (rule, value, callback) => {
                var passwordreg = /(?=.*\d)(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{6,16}/
                if (!passwordreg.test(value)) {
                  callback(new Error('密码必须由数字、字母、特殊字符组合,请输入6-16位'))
                }else{
                  callback()
                }
              }
            }
        ],
      },
      expertTypeList: ["省级专家", "市级专家", "县级专家"],
      positionList: ["主治医师"],
      departmentList: ["医学影像科", "基础医学、临床医学"],
      expertType: '',
      // 机构管理信息
      dialogTableVisible: false,
      searchOrgForm: {
        creditIdentifier: "",
        grade: "",
        organName: "",
        unitName: "",
      },
      tableOrgData: [],
      orgTotal: 0,
      regionOptions: [],
      props: {
        children: "childs",
        label: "areaName",
        checkStrictly: true,
        value: "areaName",
        emitPath: true
      },
      dialogPwsVisible: false,
      nationList:[],
      personalList:[],
      highestDegreeList:[],
    }
  },
  methods: {
    downLoad(url){
        const a = document.createElement('a')
        a.style.display = 'none'
        url=url.replace('http:','https:')
        a.download = url
        a.href = url
        document.body.appendChild(a)
        a.click()
        document.body.removeChild(a)
    },
          
    sendCode() {
      if(!this.form.telNum){
          this.$message.error("请填写手机号")
          return;
      }
      if (this.countdown > 0 || this.isSending) {
        return; // 防止重复点击发送
      }
      this.isSending = true;
      this.startCountdown();
      sms.getSmsCaptcha(this.form.telNum).then(res=>{
          this.isSending = false;
      })
    },

    startCountdown() {
      this.countdown = 60;
      const timer = setInterval(() => {
        this.countdown--;
        if (this.countdown <= 0) {
          clearInterval(timer);
        }
      }, 1000);
    },

    openOrgList () {
      this.getOrgList();
      this.dialogTableVisible = true;
    },
    exportPdf(uid){
        expertInfo.exportPdfById(uid).then(response=>{
            if(response.data.code==200 && response.data.data.fileUrl){
                const a = document.createElement('a')
                a.style.display = 'none'
                a.download = response.data.data.originName
                if(!response.data.data.fileUrl.includes("https")){
                    response.data.data.fileUrl=response.data.data.fileUrl.replace('http','https');
                }
                a.href = response.data.data.fileUrl
                document.body.appendChild(a)
                a.click()
                document.body.removeChild(a)
            }else{
                 this.$message.error("无pdf文件")
            }
        })
    },
    getList (pageInfo) {
      const param = {
        ...this.searchForm,
        ...pageInfo
      }
      let userInfo = JSON.parse(localStorage.getItem("user_info"))
      if('专家'==userInfo.roleName){
          param.uid=userInfo.uid
      }
      if(userInfo.roleName==='机构'){
          param.organUid=userInfo.uid


      }
      expertInfo.queryByPage(param).then(response => {
        console.log(response)
        this.tableData = response.data.data.rows
        this.total = response.data.data.total
        this.loading = false
      }).catch(error => {
        console.log(error)
      })
    },
    handleSearch () {
      this.$refs.pageInfo.loadData()
    },


    handleEdit () {
      this.$refs["form"].validate((valid) => {
        if (!valid) {
          return false
        }
        const param = Object.assign({}, this.form)
        formUtils.filterFormFields(param)
        expertInfo.update(param).then(result => {
          this.$message.success(result.data.msg)
          this.dialogVisible = false
          this.dialogPwsVisible = false
          this.dialogTelVisible = false
          this.handleSearch()
        }).catch(error => {
          // this.$message.error(error)
          console.log(error)
        })
      })
    },

    //暂存
    handleZancun(){
        this.form.mailAddress='0'
        this.form.status="草稿"
        this.handleEdit();
    },
    //提交
    handleSubmit(){
        if(!this.form.noticeFile){
             this.$message.error('公示文件必须上传和暂存')
             return;
        }
        if(!this.form.highestEducationLevel){
             this.$message.error('专家信息表文件必须上传和暂存')
             return;
        }
        this.form.mailAddress='1'
        this.form.status="待审核"
        this.handleEdit();
    },
    //修改密码
    passwordSave () {
      if (this.form.verifyPwd === this.form.pwd) {
        this.handleEdit()
      } else {
        this.$message.error('两次密码不同！！！')
      }
    },
    //修改手机号
    telSave () {
      if (this.form.telNum != "") {
        this.handleEdit()
      } else {
        this.$message.error('手机号不能为空！！！')
      }
    },

    showEditDialog (index, data) {
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs.form.resetFields()
        this.form = Object.assign({}, data)
        this.form.mailAddress="1"//传递一个参数，用于识别是那个操作，修改信息
        this.expertType = this.form.expertType.split('/')
        this.dialogTitle = "专家信息表"
        this.editStatus = "edit"
      })
    },

    showReadDialog (index, data) {
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs.form.resetFields()
        this.form = Object.assign({}, data)
        this.form.mailAddress="1"//传递一个参数，用于识别是那个操作，修改信息
        this.expertType = this.form.expertType.split('/')
        this.dialogTitle = "专家信息表详情"
        this.editStatus = "edit"
      })
    },

    uploadDialog (index, data) {
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs.form.resetFields()
        this.form = Object.assign({}, data)
        this.expertType = this.form.expertType.split('/')
        this.dialogTitle = "编辑专家资料"
        this.editStatus = "edit"
      })
    },
    getGradeList () {
      dictionaryInfo.queryDictionary({
        lastDict: "jigou-03"
      }).then(response => {
        this.gradeList = response.data.data.rows
        this.gradeList.sort((a, b) => {
          return a.sort - b.sort
        })
      }).catch(error => {
        console.log(error)
      })
      dictionaryInfo.queryDictionary({
        lastDict: "jigou-02"
      }).then(response => {
        this.businessNatureList = response.data.data.rows
        this.gradeList.sort((a, b) => {
          return a.sort - b.sort
        })
      }).catch(error => {
        console.log(error)
      })
    },
    // 机构管理信息
    getOrgList (pageInfo) {
      const param = {
        ...this.searchOrgForm,
        ...pageInfo
      }
      organInfo.queryByPage(param).then(response => {
        console.log(response)
        this.tableOrgData = response.data.data.rows
        this.orgTotal = response.data.data.total
        this.loading = false
      }).catch(error => {
        console.log(error)
      })
    },
    handleOrgSearch () {
      this.$refs.orgPageInfo.loadData()
    },

    selectOrg (index, data) {
      console.log(data)
      this.form.organName = data.organName;
      this.form.organUid = data.uid;
      this.form.organClassify = data.classification;
      this.form.grade = data.grade;
      this.dialogTableVisible = false;
    },
   getPositionList () {
         dictionaryInfo.queryDictionary({
           lastDict: "zhicheng"
         }).then(response => {
           this.positionList = response.data.data.rows
           this.positionList.sort((a, b) => {
             return a.sort - b.sort
           })
         }).catch(error => {
           console.log(error)
         })
         dictionaryInfo.queryDictionary({
           lastDict: "keshi"
         }).then(response => {
           this.departmentList = response.data.data.rows
           this.departmentList.sort((a, b) => {
             return a.sort - b.sort
           })
         }).catch(error => {
           console.log(error)
         })
         dictionaryInfo.queryDictionary({
           lastDict: "zhuanyelingyu"
         }).then(response => {
           this.personalList = response.data.data.rows
           this.personalList.sort((a, b) => {
             return a.sort - b.sort
           })
         }).catch(error => {
           console.log(error)
         })
       },
       getNationList () {
         dictionaryInfo.queryDictionary({
           lastDict: "nation"
         }).then(response => {
           this.nationList = response.data.data.rows
           this.nationList.sort((a, b) => {
             return a.sort - b.sort
           })
         }).catch(error => {
           console.log(error)
         })
         dictionaryInfo.queryDictionary({
           lastDict: "wenhuachengdu"
         }).then(response => {
           this.highestDegreeList = response.data.data.rows
           this.highestDegreeList.sort((a, b) => {
             return a.sort - b.sort
           })
         }).catch(error => {
           console.log(error)
         })
       },
    getData () {
      areaInfo.queryTree({}).then(result => {
        this.regionOptions = result.data.data;
        this.regionOptions = this.buildTree(this.regionOptions)
      }).catch(error => {
        console.log(error);
      })
    },
    buildTree (tree) {
      tree.forEach(item => {
        if (item.childs && item.childs.length > 0) {
          item.childs = this.buildTree(item.childs);
        } else if (item.childs && item.childs.length === 0) {
          delete item.childs;
        }
      });
      return tree;
    },
    showEditPwdDialog (index, data) {
      this.dialogPwsVisible = true
      this.form = {
        uid: data.uid,
        logName: data.logName,
        mailAddress:"2"//传递一个参数，用于识别是那个操作，修改密码
      }
    },
    showEditTelDialog (index, data) {
      this.dialogTelVisible = true
      this.form = {
        uid: data.uid,
        logName: data.logName,
        captcha:'',
        mailAddress:"3"//传递一个参数，用于识别是那个操作，修改手机号
      }
    },

    expertTypeChange (e) {
      this.form.expertType = e.join('/')
      this.$refs.expertType.dropDownVisible = false
    }
  },
  mounted () {
    this.userInfo = JSON.parse(localStorage.getItem('user_info'))
    this.handleSearch()
    this.getPositionList()
    this.getGradeList()
    this.getNationList ()
    this.getData()
  }
}
</script>

<style scoped lang="scss"></style>
